/*
 * TreeSelectionEvent.java  0.4.0 / Oct 24, 2010
 *
 * Copyright (c) 2010 - 2011, cute4j.com and contributors.
 *
 * This software is licensed under the LGPL version 2.1 license.
 * A copy of this license is included in the file LICENSE-LGPL.txt.
 */
package com.cute4j.swing.events;

import java.util.EventObject;

import com.cute4j.swing.tree.TreePath;


/**
 * Tree Selection Event.
 *
 * @author Slobodan Vrkacevic
 * @version 0.4.0
 */
public class TreeSelectionEvent extends EventObject {

// Private Static Fields. ------------------------------------------------------

  private static final long serialVersionUID = -2540334909419510158L;

// Protected Fields. -----------------------------------------------------------

  protected transient TreePath[] paths;
  protected transient boolean[] areNew;
  protected transient TreePath oldLeadSelectionPath;
  protected transient TreePath newLeadSelectionPath;

// Public Constructors. --------------------------------------------------------

  /**
   * Constructs new TreeSelectionEvent object.
   *
   * @param source Object
   * @param paths TreePath[]
   * @param areNew boolean[]
   * @param oldLeadSelectionPath TreePath
   * @param newLeadSelectionPath TreePath
   */
  public TreeSelectionEvent(Object source, TreePath[] paths,
                            boolean[] areNew, TreePath oldLeadSelectionPath,
                            TreePath newLeadSelectionPath) {
    super(source);
    this.paths = (TreePath[])paths.clone();
    this.areNew = (boolean[])areNew.clone();
    this.oldLeadSelectionPath = oldLeadSelectionPath;
    this.newLeadSelectionPath = newLeadSelectionPath;
  }

  /**
   * Constructs new TreeSelectionEvent object.
   *
   * @param source the source of the event
   * @param path the tree path
   * @param isNew <tt>true</tt> if new to the selection
   * @param oldLeadSelectionPath the old lead selection path
   * @param newLeadSelectionPath the old lead selection path
   */
  public TreeSelectionEvent(Object source, TreePath path, boolean isNew,
                            TreePath oldLeadSelectionPath,
                            TreePath newLeadSelectionPath) {
    super(source);
    paths = new TreePath[] { path };
    areNew = new boolean[] { isNew };
    this.oldLeadSelectionPath = oldLeadSelectionPath;
    this.newLeadSelectionPath = newLeadSelectionPath;
  }

// Public Methods. -------------------------------------------------------------

  /**
   * Returns tree path.
   *
   * @return tree path
   */
  public TreePath getPath() {
    return paths[0];
  }

  /**
   * Returns tree paths.
   *
   * @return tree paths
   */
  public TreePath[] getPaths() {
    return (TreePath[])paths.clone();
  }

  /**
   * Returns old lead path.
   *
   * @return old lead path
   */
  public TreePath getOldLeadSelectionPath() {
    return oldLeadSelectionPath;
  }

  /**
   * Returns new lead path.
   *
   * @return new lead path
   */
  public TreePath getNewLeadSelectionPath() {
    return newLeadSelectionPath;
  }

  // TODO: finish, fix transient bug on areNew field

}
